package com.tiku.controller;

import com.tiku.common.ResultJson;
import com.tiku.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 4个菜单相关操作
 */
@RestController
@RequestMapping("/menu")
@CrossOrigin("*")
public class UserHomeMenuController {


    @Autowired
    private MenuService menuService;

    @Autowired
    private ChapterInfoService chapterInfoService;

    @Autowired
    private ExamPaperService paperService;

    @Autowired
    private ChapterSubInfoService subInfoService;

    @Autowired
    private QuestionTableService questionTableService;


    /**
     * 获取全部菜单
     *
     * @param column
     * @return
     */
    @GetMapping("/select/column/{column}")
    public ResultJson columnList(@PathVariable("column") String column) {

        return menuService.columnList(column);
    }

    /**
     * 获取某个菜单下的所有题目
     *
     * @param chapter
     * @return
     */
    @GetMapping("/select/chapter/list/{chapter}/{specification}")
    public ResultJson chapterList(@PathVariable("chapter") String chapter,@PathVariable("specification")String specification) {

        return chapterInfoService.chapterList(chapter,specification);
    }

    /**
     * 获取小红旗题目
     *
     * @param exam
     * @return
     */
    @GetMapping("/select/exam/list/{exam}/{specification}")
    public ResultJson examList(@PathVariable("exam") String exam,@PathVariable("specification") String specification) {
        return paperService.examList(exam,specification);
    }


    /**
     * 子章节
     * @param id
     * @return
     */
    @GetMapping("/select/exam/list/child/{child}/{specification}/{menuId}")
    public ResultJson getExamChildList(@PathVariable("child") String id,@PathVariable("specification")String specification,@PathVariable("menuId")String menuId){
       return subInfoService.getExamChildList(id,specification,menuId);

    }

    /**
     * 获取某章节下所有题目
     *
     * @param id
     * @return
     */
    @GetMapping("/select/question/list/{questionId}/{specification}/{menuId}")
    public ResultJson getQuestionList(@PathVariable("questionId") String id,@PathVariable("specification")String specification,@PathVariable("menuId")String menuId){
       return questionTableService.getQuestionList(id,specification,menuId);
    }


    /**
     * 用户返回记录答题记录
     * @param id
     * @param index
     * @return
     */
    @GetMapping("/select/question/rollback/{questionId}/{index}")
    public ResultJson rollback(@PathVariable("questionId") String id,@PathVariable("index") Integer index){
        return questionTableService.rollback(id,index);
    }


}
